package com.tencent.sr.iris.basic.mp.service.convert;

import cn.hutool.core.util.StrUtil;
import com.tencent.sr.iris.activity.interfaces.enums.ActivityIdEnum;
import com.tencent.sr.iris.activity.interfaces.enums.ActivityTypeEnum;
import com.tencent.sr.iris.activity.interfaces.request.IrisPaginationRequest;
import com.tencent.sr.iris.activity.interfaces.request.acticity.ActivityStaticRequest;
import com.tencent.sr.iris.activity.interfaces.request.acticity.GetJuniorTaskRecordListRequest;
import com.tencent.sr.iris.activity.interfaces.request.acticity.LongTermAwardStaticRequest;
import com.tencent.sr.iris.activity.interfaces.request.acticity.UserTaskRecordRequest;
import com.tencent.sr.iris.activity.interfaces.response.activity.UserTaskRecordResponse;
import com.tencent.sr.iris.basic.mp.interfaces.request.MpActivityStaticRequest;
import com.tencent.sr.iris.basic.mp.interfaces.request.MpGetJuniorTaskRecordListRequest;
import com.tencent.sr.iris.basic.mp.interfaces.request.MpLongTermAwardStaticRequest;
import com.tencent.sr.iris.basic.mp.interfaces.request.MpUserTaskRecordRequest;
import com.tencent.sr.iris.basic.mp.interfaces.response.MpTaskRecordCommonResponse;
import com.tencent.sr.rmall.common.request.PaginationRequest;
import org.apache.commons.collections4.CollectionUtils;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

import java.util.*;

@Mapper(componentModel = "spring", imports = {Date.class, Objects.class, Optional.class, StrUtil.class})
public interface MpUserTaskRecordConvert {

    IrisPaginationRequest<UserTaskRecordRequest> buildUserTaskRecordRequest(PaginationRequest<MpUserTaskRecordRequest> request);
    
    LongTermAwardStaticRequest buildLongTermAwardStaticRequest(MpLongTermAwardStaticRequest request);

    @Mapping(target = "multiTask", expression = "java(StrUtil.isNotBlank(response.getGroupByExpression()))")
    MpTaskRecordCommonResponse buildMpUserTaskRecordResponse(UserTaskRecordResponse response);


    @Mapping(target = "activityTypes", expression = "java(convertActivityTypeEnums(activityStaticRequest.getActivityTypes()))")
    @Mapping(target = "activityIds", expression = "java(convertActivityIdEnums(activityStaticRequest.getActivityIds()))")
    ActivityStaticRequest buildActivityStaticRequest(MpActivityStaticRequest activityStaticRequest);


    /**
     * 活动类型转成 枚举
     *
     * @param activityTypes
     * @return
     */
    default List<ActivityTypeEnum> convertActivityTypeEnums(List<String> activityTypes) {
        ArrayList<ActivityTypeEnum> activityTypeEnums = new ArrayList<>();
        if (!CollectionUtils.isEmpty(activityTypes)) {
            for (String activityType : activityTypes) {
                activityTypeEnums.add(ActivityTypeEnum.jsonCreator(activityType));
            }
        }
        return activityTypeEnums;
    }

    /**
     * 活动id转成 枚举
     *
     * @param activityIds
     * @return
     */
    default List<ActivityIdEnum> convertActivityIdEnums(List<String> activityIds) {
        ArrayList<ActivityIdEnum> activityIdEnums = new ArrayList<>();
        if (!CollectionUtils.isEmpty(activityIds)) {
            for (String activityId : activityIds) {
                activityIdEnums.add(ActivityIdEnum.jsonCreator(activityId));
            }
        }
        return activityIdEnums;
    }

    IrisPaginationRequest<GetJuniorTaskRecordListRequest> buildJuniorTaskRecordListRequest(PaginationRequest<MpGetJuniorTaskRecordListRequest> request);
}